/*
 * halton.cpp
 *
 *  Created on: Nov 11, 2009
 *      Author: karthik
 */

#include <iostream>
#include <cmath>
#include <vector>

#include "halton.h"
#include "Utils.h"
#include "normal.h"


using namespace std;

Halton::Halton(int dim):dim_(dim){
	this->ind=0;
}

std::vector<double> Halton::getNext(){
	double remainder=0;
	int base=0;
	double output = 0.0;

	int index=this->ind;
	vector <double > rows;
	for(int j=0;j<this->dim_;j++){
		//cout<<"jth loop :"<<j <<endl;
		base=primes[j];
		double fraction = 1.0 / base;
		int N1 = 0;
		int copyOfIndex = index;

		while(copyOfIndex > 0)
		{
			N1 = (copyOfIndex / base);
			remainder = copyOfIndex % base;
			output += fraction * remainder;
			copyOfIndex = (int)(copyOfIndex / base);
			fraction /= (double)base;
		}
//		cout<<output<<endl;
//		fprintf(out1,"%.06f\t",output);

		rows.push_back(output);

		remainder=0;
		copyOfIndex=0;
		fraction=0;
		output=0.0;
	}

	this->ind++;
	return rows;
}

std::vector<double> Halton::getNextGaussian(){
	std::vector<double> ret;
	ret = normsinv_vector(this->getNext());
	return ret;
}
